/*
 * @Author: 周鹏飞
 * @Date: 2021-06-17 09:31:22
 * @LastEditors: 周鹏飞
 * @LastEditTime: 2021-07-05 10:37:00
 * @Description: file content
 */
// 查找位置
function getLedList() {
  $.ajax({
    type: 'get',
    url: httpUrl + 'led/location/list',
    data: "",
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (res) {
      console.log(res);
      if (res.code == 200) {
        $('.LED').css({ color: '#fe7272' })
        vm.$message({
          message: 'Led查询成功',
          type: 'success'
        });
        // ClearLushu('CarPolicelushu')
        // ClearLushu('csxx')
        if (res.data.length != 0) {
          vm.polymerizationemphasisLedList = [];
          for (let [key, val] of Object.entries(res.data)) {
            console.log(val.name.split(';'))
            // 位置
            let point = new BMap.Point(val.lng, val.lat)
            // 创建led图标
            var myIcon = new BMap.Icon("./images/led-on.png", new BMap.Size(50, 50));
            vm.map.centerAndZoom(new BMap.Point(111.989235, 32.790482), 11);
            var marker = new BMap.Marker(point, { icon: myIcon });
            // map.addOverlay(marker);    
            // 覆盖物标识
            marker.init = 'Led'
            vm.map.addOverlay(marker)
            marker.setTop({ isTop: true })
            //   var content = `
            //   <div id="ledBox" style="padding:10px">
            //   <div style="width: 100px; padding: 10px 0; margin: 10px 0; background: red; border-radius: 0 25px 25px 0; color: #ffffff;">
            //     &nbsp&nbsp&nbsp&nbsp led信息
            //   </div>
            //   <div id="carNumber" style="padding: 3px 10px;">
            //     名字: ${val.name}
            //   </div>

            //   <div id="carPosition" style="padding: 3px 10px;">
            //     位置:  ${val.position}
            //   </div>
            // </div>
            //   `
            //   addClickHandler(content, marker, 'Led', val.id, point) // 监控信息窗口
            // 标签创建
            var name = `
                <div class='ledName' style='width: auto; height: 22px; padding: 2px 5px; line-height: 22px; text-align: center; background:#06234b;color:#fff;'>
                  ${val.position}
                </div>`
            var Distance = val.name.length * 1

            var opts = {
              position: point,    // 指定文本标注所在的地理位置
              offset: new BMap.Size(-Distance, -5)    //设置文本偏移量
            }

            let label = new BMap.Label(name, opts);  // 创建文本标注对象
            label.init = "Led"
            label.setStyle({
              color: "#000",       //文本颜色
              fontSize: "14px",
              lineHeight: "24px",
              fontFamily: "微软雅黑",
              border: "0",
              borderRadius: '4px'
            });
            // 车辆信息聚合
            vm.polymerizationemphasisLedList.push(marker)
            vm.map.addOverlay(label);
            // let contentList=val.name.split(';')
            //  鼠标移入显示标题
            var details = `
            <div class='gundongBox' style='width:120px; height: 22px; padding: 2px 5px; line-height: 22px; text-align: center; background:#000000;color:#f75f61;'>
            ${val.ledContent.content}
            </div>`
            var Distance = val.name.length * 2.5
            var opts = {
              position: point,    // 指定文本标注所在的地理位置
              offset: new BMap.Size(-Distance, -65)    //设置文本偏移量
            }
            let xqlabel = new BMap.Label(details, opts);  // 创建文本标注对象
            xqlabel.init = "Led"
            xqlabel.setStyle({
              color: "#000",       //文本颜色
              fontSize: "14px",
              lineHeight: "24px",
              fontFamily: "微软雅黑",
              border: "0",
              borderRadius: '4px'
            });
            vm.polymerizationemphasisLedList[key].addEventListener("mouseover", function (e) {
              vm.map.addOverlay(xqlabel);
              gdong()
            });
            // 鼠标移出把标题移除
            vm.polymerizationemphasisLedList[key].addEventListener("mouseout", function (e) {
              vm.map.removeOverlay(xqlabel);
            });


          }
          vm.polymerizationemphasisLed = new BMapLib.MarkerClusterer(vm.map, {
            markers: vm.polymerizationemphasisLedList,
            styles: [{
              url: './images/jk/LedJh.png',
              size: new BMap.Size(36, 36),
              color: 'pink',
              textSize: 20,
              textColor: 'red'
            }]
          });
          // 设置最大缩放级别
          vm.polymerizationemphasisLed.setMaxZoom(11);
          searchLed()
        }
      } else if (res.code == 500) {
        vm.$message({
          message: '查询失败请联系管理员',
          type: 'error'
        });
      }
    },
    error: function (err) {
      vm.$message({
        message: '查询失败请稍后再试,或与管理员联系',
        type: 'error'
      });
    }
  })
}
// 查找led详情
// function ledDetails(){
//   $.ajax({
//     type: "POST",
//     url: httpUrl + "led/location",
//     dataType: "json",
//     contentType: "application/json",
//     headers: {
//       Authorization: localStorage.getItem('token')
//     },
//     data: JSON.stringify({
//      id:
//     }),
//     success: function (res) {
//       console.log(res);
//       vm.allList = res.data
//       vm.defaultProps.label = "name"
//     }
//   })
// }
// 搜索led
function searchLed() {
  $.ajax({
    type: "POST",
    url: httpUrl + "led/location/getLedTree",
    dataType: "json",
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    data: "{}",
    success: function (res) {
      console.log(res);
      for (let i = 0; i < res.data.length; i++) {
        res.data[i].position = res.data[i].name;
      }
      vm.allList = res.data
      vm.defaultProps.label = "position"
    }
  })
}
function gdong() {
  $('.gundongBox').liMarquee({
    direction: 'up',
    scrollamount: 10,
    circular: true,
    // runshort: false,
  });


}

